package com.zeei.bfs.controller;

import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.zeei.common.controller.BasicController;
import com.zeei.common.file.FileUploadUtil;
import com.zeei.common.vo.ResultBasicVO;
import com.zeei.common.utils.PropertiesUtil;

@Controller
@RequestMapping(value = "/bfs/fileUpload")
public class FileUploadController extends BasicController {

	@ResponseBody
	@RequestMapping(value = "/upload", method = RequestMethod.POST)
	public ResultBasicVO upload() {
		PropertiesUtil.loadProperties();

		return FileUploadUtil.upload(this.request, this.response, PropertiesUtil.getProperty("IMAGE_SETTING_DIR"));
	}

	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/download", method = RequestMethod.POST)
	public ResponseEntity<String> download(String filePath) {
		return (ResponseEntity<String>) FileUploadUtil.download(filePath);
	}

}
